package day1219;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Client1 {
    public static void main(String[] args) throws IOException {
        Client1 c=new Client1();//创建客户端对象
        c.start();
    }


    public void start() throws IOException {
        //2.用Socket的输出流给服务器发送数据
        OutputStream out=s.getOutputStream();//字节输出流
        OutputStreamWriter  writer=new OutputStreamWriter(out);//字符输出流
        PrintWriter  pw=new PrintWriter(writer);

        //输入流(读取服务端返回的数据)
        InputStream in=s.getInputStream();//用Socket获取输入流
        InputStreamReader isr=new InputStreamReader(in);//将输入流进行封装
        BufferedReader  br=new BufferedReader(isr);


        //3.用输出流给服务器发送数据
        Scanner   sc=new Scanner(System.in);
        while(true){
            System.out.println("请输入您想要发送的消息：");
            String msg=sc.nextLine();//3.1.用户用Scanner输入文字
            pw.println(msg);//3.2.用PrintWriter  pw将用户输入的文字发送到服务器
            pw.flush();
            System.out.println(  br.readLine()  );
        }
    }

    Socket s=null;
    Client1() throws IOException {
        //1.构造方法，用new Socket(信息)连接服务器
        s=new Socket("10.172.201.245",8088);
    }

}
